@use '@carbon/react/scss/themes';
@use '@carbon/react/scss/theme';

.dark .Table {
  @include theme.theme(themes.$g100);
}

.Table {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background-color: var(--cds-layer);
  width: 100%;

  .cds--toolbar-content {
    z-index: 1;

    .cds--batch-actions--active {
      // we do this because otherwise the search icon is colliding
      z-index: 2;
    }
  }

  .cds--data-table-container {
    display: flex;
    overflow: hidden;
    flex-direction: column;
    flex: 1;
    padding-top: 0;
  }

  .cds--data-table-content {
    flex: 1 1 auto;
  }

  // only this size is missing default padding
  .cds--data-table--lg td {
    padding-block: 10px;
  }

  table {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    min-width: 100% !important;
    overflow: auto;

    tr .cds--table-column-checkbox {
      padding-inline: 0.5rem;
    }
  }

  thead {
    tr {
      user-select: none;
      overflow: hidden;
      min-width: max-content !important;

      .cds--table-column-checkbox {
        display: flex;
        align-items: center;

        .cds--checkbox--inline {
          min-width: 100%;
        }
      }

      &.groupRow th {
        font-weight: normal;
      }

      th.tableHeader {
        display: flex;
      }

      .tableHeader {
        position: relative;
        line-height: normal;

        .cds--table-header-label {
          height: 100%;
          max-width: 100%;
          white-space: nowrap;
          text-overflow: ellipsis;
          overflow: hidden;
          flex-grow: 1;
          display: flex;
          align-items: center;
        }

        .text {
          white-space: nowrap;
          text-overflow: ellipsis;
          overflow: hidden;
          flex-grow: 1;
        }

        .resizer {
          display: inline-block;
          width: 10px;
          height: 100%;
          position: absolute;
          right: 0;
          top: 0;
          transform: translateX(50%);
          z-index: var(--z-above);
          overflow: hidden;

          &::after {
            content: '';
            position: absolute;
            bottom: 0;
            top: 0;
            right: 50%;
            width: 1px;
          }
        }

        &:hover .resizer::after {
          background: var(--cds-border-strong);
        }

        &.placeholder .resizer {
          display: none;
        }
      }
    }
  }

  tbody {
    overflow-y: auto;
    min-width: max-content;
    overflow-x: hidden;
    flex: auto;

    tr {
      td {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;

        &.noOverflow {
          overflow: visible;
        }

        .cds--list-box,
        .Popover,
        .Select,
        .MenuDropdown {
          block-size: 100%;
        }
      }
    }
  }

  &.noData .cds--data-table-container {
    position: relative;
  }

  &.noHighlight tbody {
    tr:not(.cds--parent-row):nth-child(even) td {
      background-color: var(--cds-layer-accent);
      border-color: var(--cds-layer-accent);
    }

    tr:not(.cds--parent-row):nth-child(odd) td {
      background-color: var(--cds-layer);
      border-color: var(--cds-layer);
    }
  }

  .noData,
  .errorContainer {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    padding: 25px;
    color: var(--grey-lighten-56);

    .NoDataNotice {
      h1,
      p {
        line-height: 1.5;
        color: var(--grey-darken-36);
      }
      h1 {
        font-weight: 600;
        font-size: 16px;
      }

      p {
        font-weight: 400;
        font-size: 14px;
      }
    }
  }

  &.loading {
    .cds--skeleton {
      table {
        overflow: hidden;

        tbody {
          overflow: hidden;
        }

        tr {
          display: flex;

          th,
          td {
            display: flex;
            flex: 1;
            align-items: center;
          }
        }
      }
    }
  }
}
